package com.loukou.lkt.lkt.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.loukou.lkt.lkt.dao.OrderOperateLogDao;
import com.loukou.lkt.lkt.entity.OrderOperateLog;
import com.loukou.lkt.lkt.enums.OrderOperateLogTypeEnum;
import com.loukou.lkt.lkt.service.OrderOperateLogService;

@Service
public class OrderOperateLogServiceImpl implements OrderOperateLogService {

	@Autowired
	private OrderOperateLogDao orderOperateLogDao;
	

	/**
	 * 
	 * @param actionEnum
	 * @param orderCode
	 * @param userId
	 * @param userName
	 * @param realName
	 * @return 记录PoPurchaseOrder的操作日志
	 */
	@Override
	public OrderOperateLog saveOrderOperateLog(
			OrderOperateLogTypeEnum actionEnum, String orderCode, int userId,
			String userName, String realName) {
		OrderOperateLog poPurchaseOperateLog = new OrderOperateLog();
		poPurchaseOperateLog.setActionType(actionEnum.getType());
		poPurchaseOperateLog.setAction(actionEnum.getComment());
		poPurchaseOperateLog.setOrderCode(orderCode);
		poPurchaseOperateLog.setUserId(userId);
		poPurchaseOperateLog.setUserName(userName);
		poPurchaseOperateLog.setRealName(realName);
		return orderOperateLogDao.save(poPurchaseOperateLog);
	}

	@Override
	public List<OrderOperateLog> findByOrderCode(String orderCode) {
		if(StringUtils.isBlank(orderCode)) {
			return new ArrayList<OrderOperateLog>();
		}
		return orderOperateLogDao.findByOrderCode(orderCode);
	}

}
